package com.ququ.syb.entrance.controller;

import com.ququ.syb.entrance.po.RequestData;
import com.ququ.syb.entrance.service.AccountService;
import com.ququ.syb.entrance.service.BalanceService;
import com.ququ.syb.entrance.vo.SybResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 生意宝账户模块
 *
 * @author Macro
 * @date 2019-08-21
 *
 */
@RestController
@RequestMapping("/syb/controller")
public class AccountController {
    @Autowired
    private AccountService accountService;
    @Autowired
    private BalanceService balanceService;

    /**
     * /p0103 查询生意宝账户
     *
     * @param header.terminalno 终端号，随便填|必填
     * @param header.requesttype 请求类型，默认为1|必填
     * @param header.operationid 请求id|必填
     * @param header.appcode 应用代码|必填
     * @param header.terminaltype 默认填1|必填
     * @param header.timestamp 时间戳|必填
     * @param encryptiontype 加密方式 1-AES加密 3-明文，这里填1|必填
     * @param accountid 生意宝账户|必填
     * @param data 业务数据请求部分，传AES加密后的空或{}即可|必填
     * @param sign 签名|必填
     * @return 当前生意宝账户基本信息
     * @respbody {"data":{"accountid":"100000000064","result":"zc6PZ6KGj/9GXfKwbKFk8Bg8NtrUSLjIEZkXOsAcHNiW5eXko6cdfLeWWYgaJx/JJqlgXNSDj9T1kClwmghVwqAveF8d1gaOHkOsggZ1BaXA3206NBAWQCu5d/0HkejyLrSUi64k09YspMC0EXIOTm5kY63GtJuB9P2myGZJh697+Csa2HMHIei4HteFKQfNnpMZ4bu68aeoW30aDf7qLSi7BbqFYM4syBbm3p2J+kRUY04uu+qh77K0emyT2ACJWMdOnsImuJzf97afJi4uCwJCxD4PYVr+a1elo2U9BZ0dlY8ffo889PgQtR9Mgjoj"},"msg":"成功","page":{"count":1,"index":1,"size":10,"total":1},"sign":"6d15de1f397ac0d5e44bcf9fa19b8d69","status":1}
     * @resp status 状态值，1-成功 其他值-失败|int
     * @resp msg 错误信息|string
     * @resp data.accountid 生意宝账号id|string
     * @resp data.result 明文 {"accountid":"100000000064","accountname":"北斗茶馆","allowpay":1,"allowwithdraw":1,"appcode":"100004","createtime":"2019-03-20 02:27:39","id":1,"lastmodifytime":"2019-03-21 01:56:29","mobile":"13950280566","name":"张三","status":1}|string
     * @resp data.result.accountid 生意宝账号id|string
     * @resp data.result.status 账户状态 1-正常 0-冻结|int
     * @resp data.result.name 姓名|string
     * @resp data.result.mobile 手机号|string
     * @resp data.result.accountname 账户名|string
     * @resp data.result.appcode 归属应用代码|string
     * @resp data.result.createtime 注册时间|string
     * @resp data.result.lastmodifytime 更新时间|string
     * @resp data.result.allowpay 允许支付 1-允许 0-禁止|int
     * @resp data.result.allowwithdraw 允许提现 1-允许 0-禁止|int
     * @resp page 分页信息，可忽略|object
     */
    @RequestMapping("/p0103")
    public SybResult getAccountInfo(@RequestHeader String appcode,
                                                   @RequestHeader(required = false) String timeStamp,
                                                   @RequestHeader(required = false) String operationid,
                                                   @RequestHeader(required = false) String operationname,
                                                   @RequestParam String accountid,
                                                   @RequestParam String data,
                                                   @RequestParam String sign,
                                                   @RequestParam Integer encryptiontype){
        RequestData<String> requestData = new RequestData<>(appcode,accountid,operationid,operationname,data,sign,encryptiontype);
        return accountService.getAccountInfo(requestData);
    }

    /**
     * /p0112 查询生意宝账户密钥
     *
     * @param header.terminalno 终端号，随便填|必填
     * @param header.requesttype 请求类型，默认为1|必填
     * @param header.operationid 请求id|必填
     * @param header.appcode 应用代码|必填
     * @param header.terminaltype 默认填1|必填
     * @param header.timestamp 时间戳|必填
     * @param encryptiontype 加密方式 填3-明文|必填
     * @param accountid 生意宝账户|必填
     * @param data 业务数据请求部分，传AES加密后的空或{}即可|必填
     * @param sign 签名
     * @return 当前生意宝账户基本信息，其中token应该取第8-24位作为密钥
     * @respbody {"status":1,"msg":"成功","data":{"accountid":"100000000064","result":{"token":"f4245ac2e14d1b981fa2771cfc3f48fd"}},"page":{"count":1,"index":1,"size":10,"total":1},"sign":"633b6c56e095b4b7ab4e01823fb0c126"}
     * @resp status 状态值，1-成功 其他值-失败|int
     * @resp msg 错误信息|string
     * @resp data.accountid 生意宝账号id|string
     * @resp data.result.token 账户token，实际使用要取其中8-24位|string
     * @resp page 分页信息，可忽略|object
     */
    @RequestMapping("/p0112")
    public SybResult getToken(@RequestHeader String appcode,
                                            @RequestHeader(required = false) String timeStamp,
                                            @RequestHeader(required = false) String operationid,
                                            @RequestHeader(required = false) String operationname,
                                            @RequestParam String accountid,
                                            @RequestParam String data,
                                            @RequestParam String sign,
                                            @RequestParam Integer encryptiontype){
        RequestData<String> requestData = new RequestData<>(appcode,accountid,operationid,operationname,data,sign,encryptiontype);
        return accountService.getToken(requestData);
    }

    /**
     * /p0107 快捷注册生意宝账户
     *
     * @param header.terminalno 终端号，随便填|必填
     * @param header.requesttype 请求类型，默认为1|必填
     * @param header.operationid 请求id|必填
     * @param header.appcode 应用代码|必填
     * @param header.terminaltype 默认填1|必填
     * @param header.timestamp 时间戳|必填
     * @param encryptiontype 加密方式 这里填3-明文|必填
     * @param accountid 生意宝账户|必填
     * @param data 业务数据请求部分，JSON格式，明文
     * @param data.mobile 注册手机号|必填
     * @param data.name 用户真实姓名
     * @param data.accountname 用户名
     * @param data.partner 渠道商accountid
     * @param data.idcard 身份证号
     * @param data.password 交易密码
     * @param sign 签名
     * @return 当前生意宝账户基本信息
     * @respbody {"status":1,"msg":"成功","data":{"accountid":"100000000109","result":{"createtime":"2019-08-26 11:56:58","mobile":"13950280566","allowpay":1,"token":"66fae80764e467c9","accountid":"100000000109","accountname":"开发测试","name":"开发测试","appcode":"100004","lastmodifytime":"2019-08-26 11:56:58","id":21,"allowwithdraw":1,"status":1}},"page":{"count":1,"index":1,"size":10,"total":1},"sign":"d2e4a713310c398febe3786da8f01b98"}
     * @resp status 状态值，1-成功 其他值-失败|int
     * @resp msg 错误信息|string
     * @resp data.accountid 生意宝账号id|string
     * @resp data.result.accountid 生意宝账号id|string
     * @resp data.result.status 账户状态 1-正常 0-冻结|int
     * @resp data.result.name 姓名|string
     * @resp data.result.mobile 手机号|string
     * @resp data.result.accountname 账户名|string
     * @resp data.result.appcode 归属应用代码|string
     * @resp data.result.createtime 注册时间|string
     * @resp data.result.lastmodifytime 更新时间|string
     * @resp data.result.allowpay 允许支付 1-允许 0-禁止|int
     * @resp data.result.allowwithdraw 允许提现 1-允许 0-禁止|int
     * @resp page 分页信息，可忽略|object
     */
    @RequestMapping("/p0107")
    public SybResult register(@RequestHeader String appcode,
                                      @RequestHeader(required = false) String timeStamp,
                                      @RequestHeader(required = false) String operationid,
                                      @RequestHeader(required = false) String operationname,
                                      @RequestParam String accountid,
                                      @RequestParam String data,
                                      @RequestParam String sign,
                                      @RequestParam Integer encryptiontype){
        RequestData<String> requestData = new RequestData<>(appcode,accountid,operationid,operationname,data,sign,encryptiontype);
        return accountService.register(requestData);
    }


    /**
     * /p0102 修改生意宝账户基本信息
     *
     * @param header.terminalno 终端号，随便填|必填
     * @param header.requesttype 请求类型，默认为1|必填
     * @param header.operationid 请求id|必填
     * @param header.appcode 应用代码|必填
     * @param header.terminaltype 默认填1|必填
     * @param header.timestamp 时间戳|必填
     * @param encryptiontype 加密方式 这里填1-AES加密|必填
     * @param accountid 生意宝账户|必填
     * @param data 业务数据请求部分，JSON格式，然后用AES加密|必填
     * @param data.mobile 注册手机号|必填
     * @param data.name 用户真实姓名
     * @param data.accountname 用户名
     * @param data.partner 渠道商accountid
     * @param data.idcard 身份证号
     * @param data.password 交易密码
     * @param sign 签名
     * @return 当前生意宝账户基本信息
     * @respbody {"status":1,"msg":"成功","data":{"accountid":"100000000064","result":"zc6PZ6KGj/9GXfKwbKFk8Bg8NtrUSLjIEZkXOsAcHNjNas414NusVj0NsfETY3Xtp59n9oW3GuxglPdDyR1E+qAveF8d1gaOHkOsggZ1BaXA3206NBAWQCu5d/0HkejyLrSUi64k09YspMC0EXIOTm5kY63GtJuB9P2myGZJh697+Csa2HMHIei4HteFKQfNnpMZ4bu68aeoW30aDf7qLe8xSGDcRGcP/5VkKbzIJgD1nukman46irgh1F9kZM1LWMdOnsImuJzf97afJi4uC/Xb/1BFTUaKfj+l2Rfe/OTr43wXTVZWNpPufT0r4sQI4uBhY7P6hQKGi2TYKy/vsg=="},"page":{"count":1,"index":1,"size":10,"total":1},"sign":"0c50ed5936b3963b4bf6727b3db27f2f"}
     * @resp status 状态值，1-成功 其他值-失败|int
     * @resp msg 错误信息|string
     * @resp data.accountid 生意宝账号id|string
     * @resp data.result 明文样本  {"accountid":"100000000064","accountname":"开发测试","allowpay":1,"allowwithdraw":1,"appcode":"100004","createtime":"2019-03-20 02:27:39","id":1,"lastmodifytime":"2019-08-26 12:01:57","mobile":"13950280566","name":"茶馆主人","status":1}
     * @resp data.result.accountid 生意宝账号id|string
     * @resp data.result.status 账户状态 1-正常 0-冻结|int
     * @resp data.result.name 姓名|string
     * @resp data.result.mobile 手机号|string
     * @resp data.result.accountname 账户名|string
     * @resp data.result.appcode 归属应用代码|string
     * @resp data.result.createtime 注册时间|string
     * @resp data.result.lastmodifytime 更新时间|string
     * @resp data.result.allowpay 允许支付 1-允许 0-禁止|int
     * @resp data.result.allowwithdraw 允许提现 1-允许 0-禁止|int
     * @resp page 分页信息，可忽略|object
     */
    @RequestMapping("/p0102")
    public SybResult modify(@RequestHeader String appcode,
                                      @RequestHeader(required = false) String timeStamp,
                                      @RequestHeader(required = false) String operationid,
                                      @RequestHeader(required = false) String operationname,
                                      @RequestParam String accountid,
                                      @RequestParam String data,
                                      @RequestParam String sign,
                                      @RequestParam Integer encryptiontype){
        RequestData<String> requestData = new RequestData<>(appcode,accountid,operationid,operationname,data,sign,encryptiontype);
        return accountService.modify(requestData);
    }




    /**
     * /p0119 修改生意宝账户支付密码
     *
     * @param header.terminalno 终端号，随便填|必填
     * @param header.requesttype 请求类型，默认为1|必填
     * @param header.operationid 请求id|必填
     * @param header.appcode 应用代码|必填
     * @param header.terminaltype 默认填1|必填
     * @param header.timestamp 时间戳|必填
     * @param encryptiontype 加密方式 这里填1-AES加密|必填
     * @param accountid 生意宝账户|必填
     * @param data 业务数据请求部分，JSON格式，然后用AES加密{}|必填
     * @param data.password 支付密码，32位md5值，小写|必填
     * @param sign 签名
     * @return 当前生意宝账户基本信息
     * @respbody {"status":1,"msg":"成功","data":{"accountid":"100000000064","result":"u/9SAcCpCjoac6eLmolpMtYGOTQwb/Fk6QsfHDB8cblP2dXAZHXAMJqXH2B8IljQExrBuFQSs1yFEr5zl2MOhDM5J9ZM23wncq/XqYqYcnnMIUDoK0ReklvS1texpLfmuKBle6cHcTI9T96/PGsIOQ=="},"page":{"count":1,"index":1,"size":10,"total":1},"sign":"bd39b705af42f38706935e222427fe38"}
     * @resp status 状态值，1-成功 其他值-失败|int
     * @resp msg 错误信息|string
     * @resp data.accountid 生意宝账号id|string
     * @resp page 分页信息，可忽略|object
     */
    @RequestMapping("/p0119")
    public SybResult setPassword(@RequestHeader String appcode,
                                    @RequestHeader(required = false) String timeStamp,
                                    @RequestHeader(required = false) String operationid,
                                    @RequestHeader(required = false) String operationname,
                                    @RequestParam String accountid,
                                    @RequestParam String data,
                                    @RequestParam String sign,
                                    @RequestParam Integer encryptiontype){
        RequestData<String> requestData = new RequestData<>(appcode,accountid,operationid,operationname,data,sign,encryptiontype);
        return accountService.setPassword(requestData);
    }


    /**
     * /p0113 查看生意宝账户通道余额
     *
     * @param header.terminalno 终端号，随便填|必填
     * @param header.requesttype 请求类型，默认为1|必填
     * @param header.operationid 请求id|必填
     * @param header.appcode 应用代码|必填
     * @param header.terminaltype 默认填1|必填
     * @param header.timestamp 时间戳|必填
     * @param encryptiontype 加密方式 这里填1-AES加密|必填
     * @param accountid 生意宝账户|必填
     * @param data 业务数据请求部分，JSON格式，然后用AES加密{}
     * @param sign 签名
     * @return 当前生意宝账户基本信息
     * @respbody {"status":1,"msg":"成功","data":{"accountid":"100000000064","result":"u/9SAcCpCjoac6eLmolpMtYGOTQwb/Fk6QsfHDB8cblP2dXAZHXAMJqXH2B8IljQExrBuFQSs1yFEr5zl2MOhDM5J9ZM23wncq/XqYqYcnnMIUDoK0ReklvS1texpLfmuKBle6cHcTI9T96/PGsIOQ=="},"page":{"count":1,"index":1,"size":10,"total":1},"sign":"bd39b705af42f38706935e222427fe38"}
     * @resp status 状态值，1-成功 其他值-失败|int
     * @resp msg 错误信息|string
     * @resp data.accountid 生意宝账号id|string
     * @resp data.result 明文样本 [{"accountid":"100000000064","balance":0,"channelid":"401","id":1,"lastmodifytime":1564754748000}]
     * @resp data.result.accountid 生意宝账号id|string
     * @resp data.result.status 账户状态 1-正常 0-冻结|int
     * @resp data.result.name 姓名|string
     * @resp data.result.mobile 手机号|string
     * @resp data.result.accountname 账户名|string
     * @resp data.result.appcode 归属应用代码|string
     * @resp data.result.createtime 注册时间|string
     * @resp data.result.lastmodifytime 更新时间|string
     * @resp data.result.allowpay 允许支付 1-允许 0-禁止|int
     * @resp data.result.allowwithdraw 允许提现 1-允许 0-禁止|int
     * @resp page 分页信息，可忽略|object
     */
    @RequestMapping("/p0113")
    public SybResult listAccountChannelBalance(@RequestHeader String appcode,
                                              @RequestHeader(required = false) String timeStamp,
                                              @RequestHeader(required = false) String operationid,
                                              @RequestHeader(required = false) String operationname,
                                              @RequestParam String accountid,
                                              @RequestParam String data,
                                              @RequestParam String sign,
                                              @RequestParam Integer encryptiontype){
        RequestData<String> requestData = new RequestData<>(appcode,accountid,operationid,operationname,data,sign,encryptiontype);
        return balanceService.listAccountChannelBalance(requestData);
    }


}
